package com.appcenter.application.controller;


import com.appcenter.application.input.Permission.CreatePermissionInput;
import com.appcenter.application.input.Permission.GetPermissionsInput;
import com.appcenter.application.input.Permission.GetPermissionsServiceInput;
import com.appcenter.application.service.PermissionService;
import com.appcenter.jz.config.ErrorJsonResult;
import com.appcenter.jz.config.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/services/jzappcenterservice/permission")
@Api("用户相关服务操作")
public class PermissionServiceController {
    @Autowired
    PermissionService PermissionService;

    @ApiOperation(value = "获取权限", notes = "获取权限",produces = "application/json")
    @PostMapping("/GetPermissions")
    public ResponseEntity<JsonResult> GetPermissions(@RequestBody GetPermissionsServiceInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setResult(PermissionService.GetPermissions(input));
        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }
}
